home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / va2.c < prev    next >
C/C++ Source or Header  |  1993-08-01  |  6KB  |  225 lines

  1. /*
  2.  *                va2.c
  3.  *
  4.  * Virtual Room Administrator for the C-86, part 2.
  5.  */
  6.  
  7. /*
  8.  *                history
  9.  *
  10.  * 88Mar27 HAW  Created.
  11.  */
  12.  
  13. #define V_ADMIN 1
  14.  
  15. #include "ctdl.h"
  16.  
  17. /*
  18.  *                contents
  19.  *
  20.  */
  21.  
  22. extern FILE       *VaLog;
  23. extern VirtualRoom *VRoomTab;
  24. extern int       VirtSize;
  25. extern VirtNet       *VirtNetList;
  26.  
  27.  
  28. extern MessageBuffer   msgBuf;    /* The -sole- message buffer    */
  29. extern CONFIG    cfg;        /* Configuration variables    */
  30. extern aRoom     roomBuf;    /* Room buffer    */
  31. extern rTable    *roomTab;
  32. extern NetTable  *netTab;
  33. extern NetBuffer netBuf;
  34. extern FILE     *netfl, *roomfl, *msgfl;
  35.  
  36. extern int     thisRoom;    /* Current room    */
  37. extern int     thisNet;    /* Current node in use    */
  38.  
  39.  
  40. /*
  41.  * NorToVirtual()
  42.  *
  43.  * This function moves msgs from msg base to virtual directory.
  44.  */
  45. int NorToVirtual(VirtNo, list)
  46. int VirtNo;
  47. TempData *list;
  48. {
  49.     int  rover, systems, i;
  50.     char *dir, fn[100];
  51.     MSG_NUMBER MsgNumber, val;
  52.     FILE *fd, *safeopen();
  53.     extern char *WRITE_ANY;
  54.  
  55.     /*
  56.      * Go through the messages
  57.      */
  58.     for (rover = 0; rover < MSGSPERRM; rover++) {
  59.     if (ReadMessage(rover)) {
  60.         if (strCmp(R_SH_MARK, msgBuf.mbaddr) == SAMESTRING ||
  61.         strCmp(NON_LOC_NET, msgBuf.mbaddr) == SAMESTRING) {
  62.         dir = LD_DIR;
  63.         MsgNumber = ++VRoomTab[VirtNo].vrHiLD;
  64.         }
  65.         else if (strCmp(LOC_NET, msgBuf.mbaddr) == SAMESTRING) {
  66.         dir = LOCAL_DIR;
  67.         MsgNumber = ++VRoomTab[VirtNo].vrHiLocal;
  68.         }
  69.         else dir = NULL;
  70.         if (dir != NULL) {
  71.         CreateVAName(fn, VirtNo, dir, MsgNumber);
  72. /*    sPrintf(fn, "virtual\\%d\\%s\\%ld", VirtNo, dir, MsgNumber); */
  73.         if ((fd = safeopen(fn, WRITE_ANY)) != NULL) {
  74.     /* fill in local node in origin fields if local message: */
  75.             if (!msgBuf.mborig[ 0])
  76.             strCpy(msgBuf.mborig,  cfg.nodeId + cfg.codeBuf  );
  77.             if (!msgBuf.mboname[0])
  78.             strCpy(msgBuf.mboname, cfg.nodeName + cfg.codeBuf);
  79.  
  80.     /* Convert # to 8-bit Citadel style for compatibility   */
  81.             if (!msgBuf.mbsrcId[0]) {
  82.             val = atol(msgBuf.mbId);
  83.             sPrintf(msgBuf.mbsrcId, "%ld %ld",
  84.                     val & 0xFFFF0000l,val & 0xFFFFl);
  85.             }
  86.  
  87.     /* send header fields out: */
  88.             if (msgBuf.mbauth[ 0]) {
  89.             fwrite("A", 1, 1, fd);
  90.             fwrite(msgBuf.mbauth, strLen(msgBuf.mbauth) + 1, 1, fd);
  91.             }
  92.             if (msgBuf.mbdate[ 0]) {
  93.             fwrite("D", 1, 1, fd);
  94.             fwrite(msgBuf.mbdate, strLen(msgBuf.mbdate) + 1, 1, fd);
  95.             }
  96.             if (msgBuf.mbtime[ 0]) {
  97.             fwrite("C", 1, 1, fd);
  98.             fwrite(msgBuf.mbtime, strLen(msgBuf.mbtime) + 1, 1, fd);
  99.             }
  100.             if (msgBuf.mboname[0]) {
  101.             fwrite("N", 1, 1, fd);
  102.             fwrite(msgBuf.mboname, strLen(msgBuf.mboname)+1, 1, fd);
  103.             }
  104.             if (msgBuf.mborig[ 0]) {
  105.             fwrite("O", 1, 1, fd);
  106.             fwrite(msgBuf.mborig, strLen(msgBuf.mborig) + 1, 1, fd);
  107.             }
  108.             if (msgBuf.mbroom[ 0]) {
  109.             fwrite("R", 1, 1, fd);
  110.             fwrite(msgBuf.mbroom, strLen(msgBuf.mbroom) + 1, 1, fd);
  111.             }
  112.             if (msgBuf.mbsrcId[0]) {
  113.             fwrite("S", 1, 1, fd);
  114.             fwrite(msgBuf.mbsrcId, strLen(msgBuf.mbsrcId)+1, 1, fd);
  115.             }
  116.             if (msgBuf.mbto[   0]) {
  117.             fwrite("T", 1, 1, fd);
  118.             fwrite(msgBuf.mbto, strLen(msgBuf.mbto) + 1, 1, fd);
  119.             }
  120.  
  121.     /* send message text proper: */
  122.             for (i = 0; msgBuf.mbtext[i]; i++)
  123.             if (msgBuf.mbtext[i] == '\n')
  124.                 msgBuf.mbtext[i] = '\r';
  125.  
  126.             fwrite(msgBuf.mbtext, strLen(msgBuf.mbtext) + 1, 1, fd);
  127.             fclose(fd);
  128.         }
  129.         else return ERROR;
  130.         for (systems = 0; systems < cfg.netSize; systems++) {
  131.             if (list[systems].uses) {
  132.             if (list[systems].mode == PEON &&
  133.                 strCmp(dir, LOCAL_DIR) == SAMESTRING)
  134. VirtNetList[systems].VirtList[list[systems].VirtIndex].LocSent = MsgNumber;
  135.             else
  136.                 if (strCmp(dir, LOCAL_DIR) == SAMESTRING &&
  137.             list[systems].WhenNormal >= roomBuf.msg[rover].rbmsgNo)
  138. VirtNetList[systems].VirtList[list[systems].VirtIndex].LocSent = MsgNumber;
  139.             else
  140.                 if (strCmp(dir, LD_DIR) == SAMESTRING &&
  141.             list[systems].WhenNormal >= roomBuf.msg[rover].rbmsgNo)
  142. VirtNetList[systems].VirtList[list[systems].VirtIndex].LDSent = MsgNumber;
  143.             }
  144.         }
  145.         }
  146.     }
  147.     }
  148. }
  149.  
  150. /*
  151.  * SetNtoVList()
  152.  *
  153.  * Beats me.
  154.  */
  155. TempData *SetNtoVList(roomNo, VNo)
  156. int roomNo, VNo;
  157. {
  158.     int rover, rooms, searcher;
  159.     TempData *list;
  160.  
  161.     list = (TempData *) GetDynamic(cfg.netSize * sizeof *list);
  162.  
  163.     for (rover = 0; rover < cfg.netSize; rover++) {
  164.     if (netTab[rover].ntflags.in_use) {
  165.         getNet(rover, &netBuf);
  166.         for (rooms = 0; rooms < SHARED_ROOMS; rooms++) {
  167.         if (isSharedRoom(rover, rooms)) {
  168.             if (netRoomSlot(rooms) == roomNo) { /* Match! */
  169.             list[rover].uses = TRUE;
  170.             if (netBuf.netRooms[rooms].mode == REG_HOST)
  171.                 list[rover].mode = PASS_BACKBONE;
  172.             else
  173.                 list[rover].mode = netBuf.netRooms[rooms].mode;
  174.  
  175.             list[rover].WhenNormal = netBuf.netRooms[rooms].lastMess;
  176.             for (searcher = 0; searcher < VIRT_LIMIT; searcher++)
  177.                 if (VirtNetList[rover].VirtList[searcher].WhichVirt
  178.                                 == -1) break;
  179.             if (searcher == VIRT_LIMIT) {
  180.                 splitIt("Table for %s is full!\n", netBuf.netName);
  181.                 list[rover].uses = FALSE;
  182.             }
  183.             else {
  184.                 list[rover].VirtIndex = searcher;
  185.                 VirtNetList[rover].VirtList[searcher].WhichVirt=VNo;
  186.                 VirtNetList[rover].VirtList[searcher].mode=
  187.                             list[rover].mode;
  188.                 splitIt("%s added.\n", netBuf.netName);
  189.             }
  190.             break;
  191.             }
  192.         }
  193.         }
  194.         if (rooms == SHARED_ROOMS)
  195.         list[rover].uses = FALSE;
  196.     }
  197.     else list[rover].uses = FALSE;
  198.     }
  199.     return list;
  200. }
  201.  
  202. /*
  203.  * ReadMessage()
  204.  *
  205.  * This function reads a message from the message base into the buffer.
  206.  */
  207. char ReadMessage(x)
  208. int x;
  209. {
  210.     extern struct mBuf mFile1;
  211.     MSG_NUMBER here;
  212.  
  213.     startAt(msgfl, &mFile1, roomBuf.msg[x].rbmsgLoc, 0);
  214.     do {
  215.     getMessage(getMsgChar, FALSE, TRUE, TRUE);
  216.     here = atol(msgBuf.mbId);
  217.     } while (here != roomBuf.msg[x].rbmsgNo &&
  218.                 mFile1.thisSector == roomBuf.msg[x].rbmsgLoc);
  219.  
  220.     if (here != roomBuf.msg[x].rbmsgNo)
  221.     splitIt("Failure to find msg %ld!\n", roomBuf.msg[x].rbmsgNo);
  222.  
  223.     return (char)(here == roomBuf.msg[x].rbmsgNo);
  224. }
  225.